package com.modebing.activiti7.controller;

import com.modebing.activiti7.service.ActivitiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("defint")
public class ActivitiDefintController {

    @Autowired
    private ActivitiService activitiService;

    /**
     * 通过文件上传部署Activiti流程
     */
    @PostMapping("deploy")
    public String deployProcess(
            @RequestParam("file") MultipartFile file,
            @RequestParam(required = false) String deploymentName) {
        return activitiService.deployProcess(file, deploymentName);
    }

    /**
     * 完成任务
     */
    @PostMapping("completeTask/{businessKey}")
    public String completeTask(@PathVariable String businessKey,
                               @RequestBody(required = false) Map<String, Object> variables) {
        return activitiService.completeTask(businessKey, variables);
    }

    /**
     * 查询流程步骤
     */
    @PostMapping("queryProcessSteps")
    public Map<String, Object> queryProcessStepsWithRejection(@RequestParam String businessKey) {
        return activitiService.queryProcessSteps(businessKey);
    }

    /**
     * 启动流程实例
     */
    @PostMapping("start")
    public String startProcess(@RequestParam String businessKey, @RequestBody Map<String, String> variables) {
        return activitiService.startProcess(businessKey, variables);
    }

    /**
     * 显示流程图
     */
    @GetMapping("process/image")
    public void getInstanceDiagramByBusinessKey(@RequestParam String businessKey, HttpServletResponse response) {
        activitiService.getInstanceDiagramByBusinessKey(businessKey, response);
    }
}
